package blog.config;

import blog.interceptor.LoginInterceptor;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.CorsRegistry;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

/**
 * @author HuLin
 * @date
 */
@Configuration
public class MyWebConfig implements WebMvcConfigurer {
    //    全局跨域设置
    @Override
    public void addCorsMappings(CorsRegistry registry) {
	  //添加跨域请求路径
	  registry.addMapping("/**")      //添加跨域请求lujing
		    .allowedOrigins("*")            //允许跨域的源（方法）
		    .allowedMethods("*")            //允许跨域请求方法
		    .allowedHeaders("*")            //允许跨域携带的请求头
		    .allowCredentials(true);            //允许携带cookie
    }

//    全局配置拦截器

    @Override
    public void addInterceptors(InterceptorRegistry registry) {
	  registry.addInterceptor(new LoginInterceptor())
		    .addPathPatterns("/blog/likes/**")
		    .addPathPatterns("/collect/**")
		    .addPathPatterns("/comment");
    }
}
